package com.example.home.metro.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.metro.bean.PathNameBean;

import java.util.List;

public class PathNameAdapter extends RecyclerView.Adapter<PathNameAdapter.MyHoldy> {
    private Context context;
    private List<PathNameBean.DataBean> list;

    public PathNameAdapter(Context context, List<PathNameBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pname, null);
        return new PathNameAdapter.MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        holder.name.setText(list.get(position).getLineName());
        int randomColor = Color.rgb((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255));
        holder.color.setBackgroundColor(randomColor);
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private TextView name;
        private TextView color;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.name);
            color = itemView.findViewById(R.id.color);
        }
    }
}
